extends CanvasLayer

var options_scene: PackedScene = preload("res://scenes/ui/options_menu.tscn")
var upgrades_scene: PackedScene = preload("res://scenes/ui/meta_menu.tscn")

func _ready() -> void:
	$%PlayButton.pressed.connect(on_play_pressed)
	$%UpgradesButton.pressed.connect(on_upgrades_pressed)
	$%OptionsButton.pressed.connect(on_options_pressed)
	$%QuitButton.pressed.connect(on_quit_pressed)


func on_play_pressed():
	ScreenTransition.transition()
	await ScreenTransition.transitioned_halfway
	get_tree().change_scene_to_file("res://scenes/main/main.tscn")

func on_upgrades_pressed():
	ScreenTransition.transition()
	await ScreenTransition.transitioned_halfway
	var upgrades_instance = upgrades_scene.instantiate()
	add_child(upgrades_instance)
	#upgrades_instance.back_pressed.connect(on_upgrades_closed.bind(upgrades_instance))

func on_options_pressed():
	ScreenTransition.transition()
	await ScreenTransition.transitioned_halfway
	var optons_instance = options_scene.instantiate()
	add_child(optons_instance)
	optons_instance.back_pressed.connect(on_optons_closed.bind(optons_instance))

func on_quit_pressed():
	get_tree().quit()

func on_optons_closed(options_instance: Node):
	options_instance.queue_free()
